/**
 * Copyright:  Copyright (c) 2013
 *
 * @FileName		: ProfitAndLossMachineAction.java
 * @PageName		: 손익현황 - 공장별
 * @Date			: 오전 11:15:31
 * @LastModifier	: 최경민
 * @LastModifyDate	: 
 * @LastModifier	: 
 * Change history	:
 */
package com.pulp.management.action;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.pulp.management.service.ManagementService;

public class ProfitAndLossMachineAction<ManagementInfo> extends ActionSupport {
	private static final long serialVersionUID = 8655623425379380497L;
	private String REQUEST_RESULT = "ok";
	static Logger logger = Logger.getLogger(ProfitAndLossMachineAction.class);

	private String errorCode = "";
	private String page;
	private String total;

	private List<ManagementInfo> profitAndLossMachineYearList = null;
	private List<ManagementInfo> profitAndLossMachineMonthList = null;
	private List<ManagementInfo> profitAndLossMachineDateList = null;

	/**
	 * @return the rEQUEST_RESULT
	 */
	public String getREQUEST_RESULT() {
		return REQUEST_RESULT;
	}

	/**
	 * @param rEQUEST_RESULT the rEQUEST_RESULT to set
	 */
	public void setREQUEST_RESULT(String rEQUEST_RESULT) {
		REQUEST_RESULT = rEQUEST_RESULT;
	}

	/**
	 * @return the logger
	 */
	public static Logger getLogger() {
		return logger;
	}

	/**
	 * @param logger the logger to set
	 */
	public static void setLogger(Logger logger) {
		ProfitAndLossMachineAction.logger = logger;
	}

	/**
	 * @return the errorCode
	 */
	public String getErrorCode() {
		return errorCode;
	}

	/**
	 * @param errorCode the errorCode to set
	 */
	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * @return the page
	 */
	public String getPage() {
		return page;
	}

	/**
	 * @param page the page to set
	 */
	public void setPage(String page) {
		this.page = page;
	}

	/**
	 * @return the total
	 */
	public String getTotal() {
		return total;
	}

	/**
	 * @param total the total to set
	 */
	public void setTotal(String total) {
		this.total = total;
	}

	/**
	 * @return the profitAndLossMachineYearList
	 */
	public List<ManagementInfo> getProfitAndLossMachineYearList() {
		return profitAndLossMachineYearList;
	}

	/**
	 * @param profitAndLossMachineYearList the profitAndLossMachineYearList to
	 *        set
	 */
	public void setProfitAndLossMachineYearList(List<ManagementInfo> profitAndLossMachineYearList) {
		this.profitAndLossMachineYearList = profitAndLossMachineYearList;
	}

	/**
	 * @return the profitAndLossMachineMonthList
	 */
	public List<ManagementInfo> getProfitAndLossMachineMonthList() {
		return profitAndLossMachineMonthList;
	}

	/**
	 * @param profitAndLossMachineMonthList the profitAndLossMachineMonthList to
	 *        set
	 */
	public void setProfitAndLossMachineMonthList(List<ManagementInfo> profitAndLossMachineMonthList) {
		this.profitAndLossMachineMonthList = profitAndLossMachineMonthList;
	}

	/**
	 * @return the profitAndLossMachineDateList
	 */
	public List<ManagementInfo> getProfitAndLossMachineDateList() {
		return profitAndLossMachineDateList;
	}

	/**
	 * @param profitAndLossMachineDateList the profitAndLossMachineDateList to
	 *        set
	 */
	public void setProfitAndLossMachineDateList(List<ManagementInfo> profitAndLossMachineDateList) {
		this.profitAndLossMachineDateList = profitAndLossMachineDateList;
	}

	/**
	 * Execute.
	 * 
	 * @return REQUEST_RESULT
	 * @throws Exception the exception
	 */
	@SuppressWarnings("unchecked")
	public String execute() throws Exception {
		System.out.println("ProfitAndLossMachineAction================");
		HttpServletRequest request = (HttpServletRequest) ServletActionContext.getRequest();

		try {
			ServletContext servletContext = ServletActionContext.getServletContext();
			WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			ManagementService managementService = (ManagementService) wac.getBean("managementService");

			profitAndLossMachineYearList = (List<ManagementInfo>) managementService.getProfitAndLossMachineYear();
			profitAndLossMachineMonthList = (List<ManagementInfo>) managementService.getProfitAndLossMachineMonth();
			profitAndLossMachineDateList = (List<ManagementInfo>) managementService.getProfitAndLossMachineDate();

			request.setAttribute("profitAndLossMachineYearList", profitAndLossMachineYearList);
			request.setAttribute("profitAndLossMachineMonthList", profitAndLossMachineMonthList);
			request.setAttribute("profitAndLossMachineDateList", profitAndLossMachineDateList);

		} catch (Exception e) {
			REQUEST_RESULT = "FALIED";
			e.printStackTrace();
		}
		return REQUEST_RESULT;
	}

}
